*Stata do file for Hansen and Jansa*
*Complexity, Resources, and Text Borrowing in State Legislatures*
*Last updated 8-11-2020*

*first, load data from your working directory or by calling it up with the full file path

use "/Hansen_Jansa_JPP_Replication.dta"

*********
*Main Text
*********

**Table 2
heckman sim expend100 salary t_slength tli model icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
heckman sim salary t_slength tli model c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)

**Figure 1
gen where = -2.2
gen pipe = "|"
quietly heckman sim salary t_slength tli model c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
qui margins, dydx(icomplex) at(expend100=(0.5(0.5)55) tli=(0) model=(0)) atmeans
marginsplot, recast(line) recastci(rarea) yline(0, lcolor(black)) plotopts(lcol(black)) ciopts(col(gs8))  addplot(scatter where expend100, ms(none) mlabel(pipe) mlabpos(0) mlabcolor(black)) legend(off) ytitle("Marginal Effect of Issue Complexity on Similarity", margin(medium)) xtitle("Staff Expenditures in $100,000s", margin(medium)) title(" ") graphregion(fcolor(white))

**Figure 2A (low expenditures)
replace where = 2
label var where " "
quietly heckman sim salary t_slength tli model c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
margins, at(expend100=(2.6) icomplex=(93(1)108) tli=(0) model=(0)) atmeans
marginsplot, recast(line) recastci(rarea) ciopts(col(gs12)) plot1opts(lcolor(black) lpattern(solid)) addplot(scatter where icomplex, ms(none) mlabel(pipe) mlabcolor(black) mlabpos(0) ysc(r(100)) ylabel(0(20)100) ytick(0(20)100) title(" ") xlab(93 "Low" 108 "High") xtitle("Complexity", margin(medsmall)) ytitle("Predicted Value of Similarity Score", margin(medsmall))) graphregion(fcolor(white)) legend(off)

**Figure 2B (high expenditures)
quietly heckman sim salary t_slength tli model c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
margins, at(expend100=(20.28) icomplex=(93(1)108) tli=(0) model=(0)) atmeans
marginsplot, recast(line) recastci(rarea) ciopts(col(gs12)) plot1opts(lcolor(black) lpattern(solid)) addplot(scatter where icomplex, ms(none) mlabel(pipe) mlabcolor(black) mlabpos(0) ysc(r(100)) ylabel(0(20)100) ytick(0(20)100) title(" ") xlab(93 "Low" 108 "High") xtitle("Complexity", margin(medsmall)) ytitle("Predicted Value of Similarity Score", margin(medsmall))) graphregion(fcolor(white)) legend(off)

**Figure 3
*you may need to install coefplot package before creating plot
*ssc install coefplot
qui heckman sim salary t_slength tli model c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
eststo m2
qui mixed sim salary t_slength tli model c.expend100##c.icomplex time order wc_log i.issuecode ||statecode: ||year:, cov(unstructured)
eststo mm2
label variable expend100 "Staff Expenditures"
label variable salary "Salary"
label variable t_slength "Session Length"
label variable tli "Term Limits"
label variable model "Model Legislation"
label variable icomplex "Complexity"
label variable time "Time"
label variable order "Order"
coefplot m2 mm2, keep(expend100 salary t_slength tli model icomplex time order) xline(0, lcol(black)) p1(label(Heckman) mcolor(black) ciopts(lcolor(black))) p2(label(Mixed Effects) mcolor(gs10) ciopts(lcolor(gs10))) graphregion(fcolor(white))

**Figure 4
graph box sim align_log100, box(1, color(gs2)) box(2, color(gs8)) graphregion(fcolor(white)) marker(1, mcolor(gs2)) marker(2, mcolor(gs8)) marker(3, mcolor(gs8)) legend(label(1 "Cosine Similarity") label(2 "Smith-Waterman Alignment"))

**Table 3
heckman sim salary t_slength tli model c.expend100##c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
heckman sim salary t_slength tli model c.expend100##c.billcomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
heckman sim salary t_slength tli model c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time icomplex) vce(cluster statecode)
heckman sim salary t_slength tli model c.expend100##c.icomplex time order, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
cmp (sim = expend100 tli icomplex wc_log model time order ||issuecode: ) (adopt = ideodist govt border_alt model pci c.time##c.time ||issuecode:), ind(adopt*1, 4) vce(cluster statecode) nolr
cmp (sim = tli c.icomplex##c.expend100 wc_log model time order ||issuecode: ) (adopt = ideodist govt border_alt model pci c.time##c.time ||issuecode:), ind(adopt*1, 4) vce(cluster statecode) nolr

**Figure 5
label define issuename 1 "Stand Your Ground" 2 "Antibullying" 3 "E-Cigarette" 4 "E-Recyle" 5 "ENDA" 6 "E-Transactions" 7 "Insurance Renewal" 8 "Safe Haven" 9 "I'm Sorry" 10 "Three Strikes" 11 "Vouchers" 12 "Asbestos Transparency" 13 "Religious Freedom" 14 "FMLA" 15 "Anatomical Gifts" 16 "Breastfeed" 17 "Undocumented Tuition" 18 "Universal Background Checks"
label values issuecode issuename
twoway (scatter billcomplex order, mcolor(black) xtitle("Order of Adoption", margin(medsmall))) (lfit billcomplex order, lcolor(black)), subtitle(, fcolor(gs14)) by(issuecode, legend(off) graphregion(fcolor(white)) note(" ") cols(3))

**Figure 6
twoway (scatter sim order, mcolor(black) xtitle("Order of Adoption", margin(medsmall))) (lfit sim order, lcolor(black)), subtitle(, fcolor(gs14)) by(issuecode, legend(off) graphregion(fcolor(white)) note(" ") cols(3))


*********
*Appendix
*********

**Table A1
sum sim, detail
sum align_log100, detail
sum icomplex, detail
sum expend100, detail
sum salary, detail
sum t_slength, detail
sum tli, detail
sum pci, detail
sum ideodist_alt, detail
sum govt, detail
sum border_alt, detail
sum wc_log, detail
sum time, detail
sum order, detail

*Figure A1
graph bar icomplex, over(issuecode, sort(1) descending label(angle(45) labsize(*0.5) ) relabel(1 "Stand Your Ground" 2 "Antibullying" 3 "E-Cigarette" 4 "E-Recyle" 5 "ENDA" 6 "E-Transactions" 7 "Insurance Renewal" 8 "Safe Haven" 9 "I'm Sorry" 10 "Three Strikes" 11 "Vouchers" 12 "Asbestos Transparency" 13 "Religious Freedom" 14 "FMLA" 15 "Anatomical Gifts" 16 "Breastfeed" 17 "Undocumented Tuition" 18 "Universal Background Checks")) graphregion(fcolor(white) margin(b+16)) bar(1, color(black)) ysc(r(120)) ylabel(0(20)120) ytick(0(20)120) ytitle("Average Complexity", margin(medsmall))

**Table A2
gen transformsim = ln(sim/(100-sim))*100
heckman transformsim expend100 salary t_slength tli model icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
heckman transformsim salary t_slength tli model c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)

**Table A3
heckman align_log100 expend100 salary t_slength tli model icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
heckman align_log100 salary t_slength tli model c.expend100##c.icomplex time order wc_log, select(ideodist_alt govt model border_alt pci c.time##c.time) vce(cluster statecode)
